package com.itheima.info.manager.system.service;

import com.itheima.info.manager.system.dao.IStudentDao;
import com.itheima.info.manager.system.domain.Student;
import com.itheima.info.manager.system.factory.Factory;

import java.util.ArrayList;

public class StudentServiceImpl implements IStudentService {

    private IStudentDao  studentDao= Factory.getStudentDao();
    @Override
    public void addStudent(Student student) {
        studentDao.addStudent(student);
    }

    @Override
    public void deleteStudent(String id) {
studentDao.deleteStudent(id);
    }

    @Override
    public void updateStudent(String id, Student newStu) {
studentDao.updateStudent(id,newStu);
    }

    @Override
    public ArrayList<Student> findAllStudent() {
        return studentDao.findAllStudent();
    }

    @Override
    public boolean isExits(String id) {
        ArrayList<Student> allStudent = studentDao.findAllStudent();

        for (int i = 0; i < allStudent.size(); i++) {
            //allStudent.get(i)
            Student student = allStudent.get(i);
            if(student!=null&&student.getId().equals(id)){
                return true;
            }
        }
        return false;
    }
}
